package com.iotproject.studyservice.controller;


import com.iotproject.commonutils.R;
import com.iotproject.studyservice.entity.StudyListening;
import com.iotproject.studyservice.service.StudyListeningService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 听力 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2023-04-08
 */
@RestController
@RequestMapping("/studyservice/study-listening")
public class StudyListeningController {

    @Autowired
    StudyListeningService studyListeningService;

    @PostMapping("/insertStudyListening")
    public R insertStudyListening() {
        for (int i = 0; i < 12; i++) {
            StudyListening studyListening = new StudyListening();
            studyListening.setName("名字");
            studyListening.setContent("内容");
            studyListening.setTypeId("id");
            studyListeningService.save(studyListening);
        }
        return R.ok();
    }

    @GetMapping("getStudyListeningList/{typeId}")
    public R getStudyListeningList(@PathVariable("typeId") String typeId) {
        QueryWrapper<StudyListening> studyListeningQueryWrapper = new QueryWrapper<>();
        studyListeningQueryWrapper.eq("type_id", typeId);
        List<StudyListening> list = studyListeningService.list(studyListeningQueryWrapper);
        return R.ok().data("list", list);
    }

    //根据listeningId获取listening
    @GetMapping("getStudyListening/{listeningId}")
    public R getStudyListening(@PathVariable("listeningId") String listeningId) {
        StudyListening studyListening = studyListeningService.getById(listeningId);
        return R.ok().data("studyListening", studyListening);
    }

}

